package nl.blindwars.mapeditor.gui;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Point;

import javax.swing.ImageIcon;
import javax.swing.JFrame;

public class Window extends JFrame {
	private static final long serialVersionUID = -8475328248383801047L;

	private StatusBar statusBar;
	
	private DrawWindow drawWindow;
	
	private int height = 480;
	private int width = 800;
	
	public Window() {
		super();		
		createAndAddPanels();
		init();
	}
	
	private void init() {
		setTitle("Map editor v0.1");
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		// FIXME: Place the window in the center of the screen.
//		setLocationRelativeTo(null); // Doesn't work on linux.
		setResizable(false);
		setSize(width, height);
		setIconImage(new ImageIcon("icon_nuke.gif").getImage());
		setVisible(true);
	}
	
	public void createAndAddPanels() {
		Container c = getContentPane();
		c.setLayout(new BorderLayout());
		
		drawWindow = new DrawWindow(this, width - 140, height);
		c.add(drawWindow, BorderLayout.CENTER);
		
		MenuPanel menu = new MenuPanel(this, 140, height);
		c.add(menu, BorderLayout.EAST);
		
		statusBar = new StatusBar(width);
		c.add(statusBar, BorderLayout.SOUTH);
	}
	
	public void setMouseCoordinates(Point p) {
		statusBar.setMouseCoordinates(p);
	}
	
	// TODO: Discuss with Matthijs: pass drawwindow to menupanel? or process everything through the main window?
	public void toggleDrawMode() {
		drawWindow.toggleDrawMode();
	}
}
